from itsdangerous import TimedJSONWebSignatureSerializer as Serializer, BadData
from django.conf import settings

def generate_openid_signature(openid):
    serializer = Serializer(settings.SECRET_KEY, 600)
    data = {'openid':openid}
    token = serializer.dumps(data)
    return token.decode()

def check_openid_signature(openid_sign):
    serializer = Serializer(settings.SECRET_KEY, 600)
    try:
        data = serializer.loads(openid_sign)
        return data.get('openid')
    except BadData:
        return None